home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 3222 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: castle.nando.net!news
  2. From: sekruege@nando.net (Steve Krueger)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: SAS/C fopen("foo","a") -- is this a bug?
  5. Date: 9 Feb 1996 04:03:31 GMT
  6. Organization: News & Observer Public Access
  7. Message-ID: <4feh2j$7im@castle.nando.net>
  8. References: <zpfaa8aCCygGZ1@da23.darkness.gun.de>
  9. NNTP-Posting-Host: grail813.nando.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=iso-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-NewsReader: Interworks_GRn 3.0 January 12, 1996
  14.  
  15. In article <zpfaa8aCCygGZ1@da23.darkness.gun.de> zodiac@darkness.gun.de (Ralph Seichter) writes:
  16. : I used the following test program:
  17. : ----------8<----------8<----------8<----------8<----------8<----------
  18. : /* test.c */
  19. : #include <stdio.h>
  20. : void main(void)
  21. : {
  22. :     FILE *file;
  23. :     if (file = fopen("foo", "w"))
  24. :     {
  25. :         if (fprintf(file, "bar", 3) == 3)
  26. :             printf("write ok\n");
  27. :         fclose(file);
  28. :     }
  29. :     if (file = fopen("foo", "a"))
  30. :     {
  31. :         if (fprintf(file, "bar", 3) == 3)
  32. :             printf("append ok\n");
  33. :         fclose(file);
  34. :     }
  35. : }
  36. : ----------8<----------8<----------8<----------8<----------8<----------
  37. : After I compiled this with SAS/C 6.56, I did the following in a shell:
  38. :    1> sc link test.c
  39. :    1> date >foo
  40. :    1> protect foo r
  41. :    1> test
  42. :    append ok
  43. : The first fopen() with mode "w" fails, which is correct. But why can the
  44. : write-protected file "foo" be opened with mode "a", and why won't fprintf()
  45. : return an error? The file's contents are not changed, as is to be expected,
  46. : but fprintf() reports that three bytes were written, which is not true.
  47.  
  48.  
  49. Here's what's happening. The fopen() "a" mode is translated to an
  50. Open() with MODE_OLDFILE, which succeeds, so the fopen() works.
  51.  
  52. The fprintf eventually calls Write(), and that returns a success
  53. code too. Also, on my machine, the contents of foo are added to,
  54. so the routines in SC.LIB get no indication that the file
  55. is read only. 
  56.  
  57. I guess the only way to make this work as expected would be to 
  58. have the level 1 SAS/C routines examine the protection bits
  59. before doing the Open(). They currently do not look at the
  60. protection bits in any way.
  61.  
  62. sk
  63.